package com.liner;

import java.util.Arrays;
import java.util.Scanner;

public class CalTotalAvg {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        /*
         * 《主持人大赛》  有6名评委给选手打分
         *  分数范围 0~100
         *  选手最高得分为：   去掉最高分，去掉最低分  求剩余平均分
         */

        System.out.print("请输入本场有几位评委:");
        int count = scanner.nextInt();
        double[] scores = inputData(count);

        double avg = calAvg(scores);
        System.out.println("本场平均分为：" + avg);
    }

    /**
     * 控制台输出评委打分
     */
    public static double[] inputData(int count) {

        double[] scores = new double[count];
        for (int i = 0; i < count; i++) {
            System.out.print("第" + (i + 1) + "位评委的打分为:");
            scores[i] = scanner.nextDouble();
            if (scores[i] < 0 || scores[i] > 100) {
                System.out.println("请输入0~100区间的分数");
                break;
            }
        }
        return scores;
    }

    /**
     * 算出平均分
     */
    public static double calAvg(double[] scores) {
        double sum = calTotal(scores);
        //算出平均分
        return sum / (scores.length - 2);
    }

    /**
     * 算出总分
     */
    private static double calTotal(double[] scores) {
        double sum = 0;
        //数组升序排序
        Arrays.sort(scores);
        //取出去掉一个最高分去掉一个最低分
        for (int i = 1; i < scores.length - 1; i++) {
            sum += scores[i];
        }
        return sum;
    }

}
